package com.djnt.catering.sales_promotion;

import android.app.ListActivity;
import android.content.ContentUris;
import android.content.Intent;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.widget.ListView;

import com.djnt.catering.R;
import com.djnt.catering.database.HotNews;
import com.djnt.catering.database.ViewHotNewsUsers;

public class SalesPromotionList extends ListActivity {

	protected static final String TAG = "SalesPromotionList";
	private SalesPromotionListAdapter mAdapter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		Cursor c = this.getContentResolver().query(HotNews.CONTENT_URI, null,
				null, null, HotNews.DEFAULT_SORT_ORDER);
		mAdapter = new SalesPromotionListAdapter(this,
				R.layout.sales_promotion_list_item, c);
		setListAdapter(mAdapter);

	}

	@Override
	protected void onListItemClick(ListView l, View v, int position, long id) {
		// TODO Auto-generated method stub
		Intent i = new Intent(this, SalesPromotionUserView.class);
		i.setData(getSelectedUri(position));
		startActivity(i);
	}

	private Uri getSelectedUri(int position) {
		if (position == ListView.INVALID_POSITION) {
			throw new IllegalArgumentException("Position not in list bounds");
		}

		final long id = mAdapter.getItemId(position);
		return ContentUris.withAppendedId(ViewHotNewsUsers.CONTENT_URI, id);
	}

}
